package com.mes.defece.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mes.common.pojo.MESResult;
import com.mes.defece.mapper.DefeceMapper;
import com.mes.defece.service.DefeceService;
import com.mes.pojo.defece.Defece;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @Author 侯伟豪
 * @Company 起点编程
 * @Description
 * @Time 2024/10/16 18:57
 */
@Service
public class DefeceServiceImpl implements DefeceService {
    @Autowired
    private DefeceMapper defeceMapper;

    @Override
    public MESResult selectCount(Defece defece, Integer page, Integer limit) {
        PageHelper.startPage(page, limit);
        List<Defece> defeces = defeceMapper.selectAll(defece);
        return MESResult.success(new PageInfo<>(defeces));
    }

    @Override
    public MESResult addDefece(Defece defece) {
        if (defece.getDefeceStatus() == null){
            defece.setDefeceStatus(1);
        }
        return MESResult.success(defeceMapper.insert(defece));
    }

    @Override
    public MESResult selectById(Long defeceId) {
        return MESResult.success(defeceMapper.selectById(defeceId));
    }

    @Override
    public MESResult updateDefece(Defece defece) {
        return MESResult.success(defeceMapper.updateDefeceById(defece));
    }

    @Override
    public MESResult updateDefeceStatus(Long defeceId, Integer defeceStatus) {
//        将状态修改为99，模拟删除
        Defece defece = new Defece();
        defece.setDefeceId(defeceId);
        defece.setDefeceStatus(99);
        return MESResult.success(defeceMapper.updateDefeceStatus(defece));
    }

}